<?php


namespace App\Http\Controllers\Warehousing;


use App\Http\Controllers\Controller;
use App\Http\Requests\Warehousing\Shelves\ShelvesRequest;
use App\Http\Searchs\Warehousing\ShelvesSearch;
use App\Repositories\Shelves;
use Illuminate\Support\Facades\DB;

class ShelvesController extends Controller
{
    /**
     * @var Shelves
     * @author luffyzhao@vip.126.com
     */
    private $shelves;

    /**
     * ShelvesController constructor.
     * @param Shelves $shelves
     * @author luffyzhao@vip.126.com
     */
    public function __construct(Shelves $shelves)
    {
        $this->shelves = $shelves;
    }

    /**
     * @param ShelvesSearch $search
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function index(ShelvesSearch $search)
    {
        return $this->response(
            $this->shelves->paginate($search->toArray())
        );
    }

    /**
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function edit($id){
        return $this->response(
            $this->shelves->edit($id)
        );
    }
    /**
     * @param ShelvesRequest $request
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function shelves(ShelvesRequest $request, $id)
    {
        return $this->response(
            DB::transaction(function () use ($id, $request) {
                $this->shelves->shelves($id, $request->only(['code']));
            })
        );
    }
}
